﻿using Base.Service.Interface;
using HZL.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Base.Api.Admin.Controllers
{

    
    [Route("api/[controller]/[action]")]
    /*[ApiExplorerSettings(GroupName = "WeChat")]*///分组
    [ApiController]

    public class weixinController : BaseController
    {
        /// <summary>
        /// （获取用户信息）请传输自己的appid和secret
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        [Filters.ActionLog(group = "测试", name = "微信测试")]
        //[Authorize]
        public IActionResult GetOpenID(string code,string appid,string secret)
        {
            string url = $@"https://api.weixin.qq.com/sns/jscode2session?appid={appid}&secret={secret}&js_code={code}&grant_type=authorization_code";
            var result = Http.Get(url);
            JObject jo = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
            string openid = jo["openid"].ToString();
            return Ok(new
            {
                openid
            });
        }

      
    }
}
